package com.scada.service.impl;

import java.util.HashMap;
import java.util.Map;

import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.scada.dao.IMemberReturnVisitDao;
import com.scada.inf.MemberReturnVisitor;
import com.scada.model.bean.MemberReturnVisit;
import com.scada.model.result.ResponseBean;
import com.scada.model.search.MemberReturnVisitSearch;

@Service("memberReturnVisitorService")
@WebService
@SOAPBinding(style = Style.RPC)
public class MemberReturnVisitorImpl implements MemberReturnVisitor{

	@Autowired
	private IMemberReturnVisitDao memberReturnVisitDao;
	
	@Transactional
	@Override
	public void deleteMemberReturnVisitById(String isShow, String ids) {
		
		try {
			Map<String,Object> map = null;
			for(String id : ids.split(",")) {
				map = new HashMap<String,Object>(); 
				map.put("isShow", isShow);
				map.put("id", Long.parseLong(id));
				memberReturnVisitDao.deleteMemberReturnVisitById(map);
			}
		}catch (Exception e) {
			throw new RuntimeException();
		}
	}

	@Override
	public ResponseBean insertMemberReturnVisit(MemberReturnVisit memberReturnVisit) {
		
		ResponseBean responseBean = new ResponseBean();
		try{
			memberReturnVisitDao.insertMemberReturnVisit(memberReturnVisit);
			responseBean.success();
		}catch(Exception e){
			responseBean.failed();
		}
		return responseBean;
	}

	@Override
	public ResponseBean getMemberReturnVisitById(Long id) {
		
		ResponseBean responseBean = new ResponseBean();
		try{
			responseBean.addObject("result", memberReturnVisitDao.getMemberReturnVisitById(id));
			responseBean.success();
		}catch(Exception e){
			responseBean.failed();
		}
		return responseBean;
	}

	@Override
	public ResponseBean updateMemberReturnVisit(MemberReturnVisit memberReturnVisit) {
		
		ResponseBean responseBean = new ResponseBean();
		try{
			memberReturnVisitDao.updateMemberReturnVisit(memberReturnVisit);
			responseBean.success();
		}catch(Exception e){
			responseBean.failed();
		}
		return responseBean;
	}

	@Override
	public ResponseBean getMemberReturnVisitPageData(MemberReturnVisitSearch memberReturnVisitSearch) {
		
		ResponseBean responseBean = new ResponseBean();
		Map<String,Object> map = new HashMap<String,Object>();
		try{
			map.put("isShow", MemberReturnVisit.IsShowCode.YES.getKey());
			map.put("memberId", memberReturnVisitSearch.getMemberId());
			map.put("startDate", memberReturnVisitSearch.getStartDate());
			map.put("endDate", memberReturnVisitSearch.getEndDate());
			responseBean.addObject("resultCount", memberReturnVisitDao.getMemberReturnVisitPageCount(map));
			map.put("start", memberReturnVisitSearch.getStart());
			map.put("pageSize", memberReturnVisitSearch.getLength());
            responseBean.addObject("resultList", memberReturnVisitDao.getMemberReturnVisitPageList(map));
			responseBean.success();
		}catch(Exception e){
			responseBean.failed();
		}
		return responseBean;
	}

	

}
